package prototype.deep;

import java.io.*;
import java.util.Date;

/**
 * @author Feng
 * @date 2019/3/11 23:01
 */
public class QiTianDasheng extends Monkey implements Cloneable, Serializable {
    public JinGuBang jinGuBang;

    public QiTianDasheng(){
        this.birthday = new Date();
        this.jinGuBang = new JinGuBang();
        this.height = 180;
        this.weight = 80;
    }



    public Object deepClone(){
        try{
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(byteArrayOutputStream);
            oos.writeObject(this);

            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
            ObjectInputStream ois = new ObjectInputStream(byteArrayInputStream);

            QiTianDasheng copy = (QiTianDasheng) ois.readObject();
            copy.birthday = new Date();
            byteArrayInputStream.close();
            oos.close();
            byteArrayOutputStream.close();
            ois.close();
            return copy;
        }
        catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    public QiTianDasheng shallowClone(QiTianDasheng target){
        QiTianDasheng qiTianDasheng = new QiTianDasheng();
        qiTianDasheng.height = target.height;
        qiTianDasheng.weight = target.weight;
        qiTianDasheng.jinGuBang = target.jinGuBang;
        qiTianDasheng.birthday = new Date();

        return qiTianDasheng;
    }

}
